"""
金融监控系统后端服务
使用 FastAPI 框架
"""
import sys
import os

# 将app目录添加到Python路径
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'app'))

from app.main import app

if __name__ == "__main__":
    import uvicorn
    from app.core.config import settings
    import logging
    
    # 禁用watchfiles的日志输出
    logging.getLogger("watchfiles.main").setLevel(logging.CRITICAL)
    
    # 配置Uvicorn参数
    uvicorn_args = {
        "app": "app.main:app",
        "host": settings.HOST,
        "port": settings.PORT,
        "log_level": settings.LOG_LEVEL
    }
    
    # 如果启用了调试模式，则配置文件监视
    if settings.DEBUG:
        uvicorn_args["reload"] = True
        # 设置重载延迟以减少频繁重启
        uvicorn_args["reload_delay"] = 1.0
        # 排除不需要监视的目录和文件
        uvicorn_args["reload_excludes"] = [
            "logs/*",
            "logs/**/*",
            "*.log",
            "tmp/*",
            ".git/*",
            ".git/**/*",
            "__pycache__/*",
            "__pycache__/**/*",
            "*.pyc",
            "*.pyo",
            "*~",
            ".DS_Store"
        ]
        # 明确指定需要监视的目录
        uvicorn_args["reload_dirs"] = ["app/"]
    
    uvicorn.run(**uvicorn_args)